package com.netty.pro.netty.nianbao_chaibao;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author xuzn
 * @ClassName: SendMessageDecoder
 * @ProjectName netty-pro
 * @date 2020/3/23/10:50
 */
public class SendMessageDecoder extends ReplayingDecoder<Void> {
  @Override
  protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    System.out.println("SendMessageDecoder decode方法被调用");
    //  二进制字节码转成message
    int len = in.readInt();
    byte[] content = new byte[len];
    in.readBytes(content);
    SendMessage sendMessage = new SendMessage();
    sendMessage.setLen(len);
    sendMessage.setContent(content);
    out.add(sendMessage);
  }
}
